package com.dede.baselib.state

import android.view.View
import com.dede.baselib.R
import com.dede.rxbase.fragment.BaseFragment
import com.dede.state.StateProxy
import com.dede.state.commons.register
import com.dede.state.component.StateComponent

/**
 * @author hsh
 * @date 2018/1/23 15:10.
 * @doc
 */
class StateFragment : BaseFragment(), View.OnClickListener {

    private lateinit var stateProxy: StateProxy

    override fun getLayoutId() = R.layout.fragment_test

    override fun initView() {
        stateProxy = register(StateComponent.ReloadListener {
            stateProxy.show(Loading::class.java)
        })
        view!!.findViewById<View>(R.id.bt_loading).setOnClickListener(this)
        view!!.findViewById<View>(R.id.bt_empty).setOnClickListener(this)
        view!!.findViewById<View>(R.id.bt_error).setOnClickListener(this)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.bt_empty -> stateProxy.show(Empty::class.java)
            R.id.bt_error -> stateProxy.show(Error::class.java)
            R.id.bt_loading -> stateProxy.show(Loading::class.java)
        }
    }
}
